package cn.gd.controller.Administrative;

import cn.gd.pojo.Meetingrooms;
import cn.gd.service.Administrative.AdministrativeService;
import cn.gd.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wyh
 * @version 1.80
 */
@CrossOrigin
@RestController
@RequestMapping("/administrative")
public class AdministrativeController {

    @Autowired
    private AdministrativeService administrativeService;

    @GetMapping("/getMeetingRoomsAll/{pageNo}/{pageSize}")
    public Result<PageInfo<Meetingrooms>> getMeetingRoomsAll(@PathVariable Integer pageNo,
                                                             @PathVariable Integer pageSize){
        return Result.ok(administrativeService.getMeetingRoomsAll(pageNo,pageSize));
    }

    @GetMapping("/getMeetingRoomsId/{id}")
    public Result<Meetingrooms> getMeetingRoomsId(@PathVariable Integer id){
        return Result.ok(administrativeService.getMeetingRoomsId(id));
    }

    @PutMapping("/updateMeetingRooms")
    public Result<Map<String,String>> updateMeetingRooms(@RequestBody Meetingrooms meetingrooms){
        int num = administrativeService.updateMeetingRooms(meetingrooms);
        Map<String, String> map = new HashMap<>();
        if (num > 0) {
            map.put("result", "true");
        } else {
            map.put("result", "false");
        }
        return Result.ok(map);
    }

    @DeleteMapping("/deleteMeetingRooms/{id}")
    public Result<Map<String,String>> deleteMeetingRooms(@PathVariable Integer id){
        int num = administrativeService.deleteMeetingRooms(id);
        Map<String, String> map = new HashMap<>();
        if (num > 0) {
            map.put("result", "true");
        } else {
            map.put("result", "false");
        }
        return Result.ok(map);
    }

    @PostMapping("/addMeetingRooms")
    public Result<Map<String,String>> addMeetingRooms(@RequestBody Meetingrooms meetingrooms){
        int num = administrativeService.addMeetingRooms(meetingrooms);
        Map<String, String> map = new HashMap<>();
        if (num > 0) {
            map.put("result", "true");
        } else {
            map.put("result", "false");
        }
        return Result.ok(map);
    }
}
